﻿@{
    ViewBag.Title = "仓库定义";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    $(function () {
        initControl();
        gridList();
    });
    function initControl() {
       //仓库类别
        $("#txtFStoreType").bindSelect({
            url: "/VBaseData/V_BUS_SJ_Dictionary/GetStoreType",
            id: "FTypeNO",
            text: "FTypeName"
        });
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/VBaseData/V_CPK_ZD_11_DatStoreHouse/GetList",
            height: $(window).height() - 152,
            colModel: [
                { label: '仓库id', name: 'FStoreID', width: 80, align: 'center', hidden: true },
                { label: '仓库编号', name: 'FStoreNO', width: 80, align: 'center' },
                { label: '仓库名称', name: 'FStoreName', width: 80, align: 'left' },
                { label: '负责人员', name: 'FResPerson', width: 80, align: 'left' },
                { label: '仓库类型', name: 'FStoreType', width: 80, align: 'center', hidden: true },
                { label: '仓库类型名称', name: 'FStoreTypeName', width: 80, align: 'left' },
                { label: '创建人员', name: 'FCreateBy', width: 80, align: 'left' },
                { label: '创建日期', name: 'FCreateDate', width: 80, align: 'left' },
                { label: '创建时间', name: 'FCreateTime', width: 80, align: 'left' },
                { label: '更改人员', name: 'FUpdateBy', width: 80, align: 'left' },
                { label: '更改日期', name: 'FUpdateDate', width: 80, align: 'left' },
                { label: '更改时间', name: 'FUpdateTime', width: 80, align: 'left' },
                { label: '', name: '', width: 80, align: 'center' }
            ],
            pager: "#gridPager",
            sortname: 'FStoreNO asc,FCreateBy desc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                var rowData = $gridList.jqGrid('getRowData', rowId);
                $("#rowID").val(rowId);
                $("#txtFStoreID").val(rowData.FStoreID);
            },
            gridComplete: function () {
                if ($("#txtFStoreNO").val() != "") {
                    $("#gridList").find('[title="' + $("#txtFStoreNO").val() + '"]').each(function () {
                        var rowid = $(this).parent().attr("id");
                        $("#gridList").setSelection(rowid);
                    });
                }
        }
        });
        $("#btn_search").click(function () {
            Query();
        });
    }
    function Query() {
        var $gridList = $("#gridList");
        $gridList.jqGrid('setGridParam', {
            postData: { FStoreNO: $("#txtqueryFStoreNO").val(), FStoreName: $("#txtqueryFStoreName").val(), FResPerson: $("#txtqueryFResPerson").val() },
        }).trigger('reloadGrid');
    }
    function btn_choose() {
        var title = '选择负责人员';
        var url = '/MainData/Storage/ChoosePeople?data=' + escape($("#txtFResPerson").val());
        $.detailOpen2({
            id: "Detail",
            title: title,
            url: url
        });
    }
    function getData(data) {
        $("#txtFResPerson").val(data);
    }
    function btn_Add() {
        $('#form2').show();
    }
    function btn_Save() {
        var postData = $("#form2").formSerialize();
        
        if (postData["FStoreNO"] == "") {
            $.modalAlert("仓库编号不能为空", "error");
            return false;
        }
        if (postData["FStoreName"] == "") {
            $.modalAlert("仓库名称不能为空", "error");
            return false;
        }
        if (postData["FResPerson"] == "") {
            $.modalAlert("负责人员不能为空", "error");
            return false;
        }
        $.submitForm({
            url: "/MainData/Storage/SubmitForm",
            param: postData,
            success: function () {
                $("#gridList").trigger("reloadGrid");
            }
        });
    }
    function btn_Del() {
        var postData = $("#txtFStoreID").val();
        $.deleteForm({
            url: "/MainData/Storage/DeleteForm",
            param: { storeID: postData },
            success: function () {
                $("#gridList").trigger("reloadGrid");
            }
        })
    }

    function btn_Edit() {
        var rowData=$("#gridList").jqGrid('getRowData', $("#rowID").val());
        $("#txtFStoreNO").val(rowData.FStoreNO);
        $("#txtFStoreName").val(rowData.FStoreName);
        $("#txtFResPerson").val(rowData.FResPerson);
        $("#txtFStoreType").val(rowData.FStoreType).trigger("change");
        $("#form2").show();
    }

    function btn_Cancel() {
        $("#txtFStoreNO").val("");
        $("#txtFStoreName").val("");
        $("#txtFResPerson").val("");
        $("#txtFStoreType").val("")
        $('#form2').hide();
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <input id="txtFStoreID" type="hidden"/>
    <input id="rowID"  type="hidden" />
    <form id="form1">
        <div style="padding: 12px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc;" class="line-table input-width-140">

            <div class="btn-group" style="margin-top:-9px;">
                仓库编号<br /><input id="txtqueryFStoreNO" name="FStoreNO" maxlength="4" placeholder="" type="text" class="form-control required" /> &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                仓库名称<br /><input id="txtqueryFStoreName" name="FStoreName" placeholder="" type="text" class="form-control required" /> &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                负责人员<br /><input id="txtqueryFResPerson" name="FResPerson" placeholder="" type="text" class="form-control required" /> &nbsp;
            </div>

            <div class="btn-group" style="">
                <a id="btn_search" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div class="btn-group" style="float:right;">
                <a id="" class="btn btn-primary center-block" onclick="Query()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a class="btn btn-primary center-block active" onclick="btn_Add()">   <span class="glyphicon glyphicon-plus">    </span>&nbsp输入</a>
                <a class="btn btn-primary center-block active" onclick="btn_Del()">   <span class="glyphicon glyphicon-plus">    </span>&nbsp删除</a>
                <a class="btn btn-primary center-block active" onclick="btn_Edit()">  <span class="glyphicon glyphicon-plus">    </span>&nbsp修改</a>
            </div>
        </div>
    </form>

    <form id="form2" style="display:none;">
        <div style="padding: 5px 0; padding-left:15px; margin-right: 30px;" class="line-table input-width-140">
            <label class="prefix">仓库编号</label> <input id="txtFStoreNO" maxlength="2" name="FStoreNO"  type="text" class="form-control formValue required" /> &nbsp;
            <label class="prefix">仓库名称</label>  <input id="txtFStoreName" name="FStoreName" type="text" class="form-control formValue required" /> &nbsp;
            <label class="prefix">负责人员</label>  <input id="txtFResPerson" name="FResPerson" type="text" readonly="readonly" class="form-control formValue required" placeholder="">
            <div class="btn-group" style="margin-top:-1px;">
                <a id="" class="btn btn-primary center-block btn-1" onclick="btn_choose()"><span class="glyphicon glyphicon-plus"></span> 选择</a>
            </div> &nbsp;
            <label class="prefix">仓库类型</label> <select id="txtFStoreType" name="FStoreType" class="form-control formValue required"></select> &nbsp;
            <div class="btn-group" style="margin-top:-1px;">
                <a  class="btn btn-primary center-block btn-1" onclick="btn_Save()"><span class="glyphicon glyphicon-ok"></span> 保存</a>
            </div>
            &nbsp;&nbsp;&nbsp;
            <div class="btn-group" style="margin-top:-1px;">
                <a id="" class="btn btn-primary center-block btn-1" onclick="btn_Cancel()"><span class="glyphicon glyphicon-remove"></span> 取消</a>
            </div>
        </div>
    </form>
    <div style="">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</div>

